package com.study.fetch;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import jodd.util.StringUtil;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.collections4.CollectionUtils;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 * @author zhuzi
 * 2023/9/21 16:29
 * 搜狐日K线
 */
@Data
@Accessors(chain = true)
public class HistPriceZsDTO {
    private int status;

    private List<String> dividend;

    private String type;

    private String statusmsg;

    private List<List<String>> dataBasic;

    private List<List<String>> dataDiv;

    @Data
    @Accessors(chain = true)
    @ExcelIgnoreUnannotated
    public static class HistDetailDTO {
        @ExcelProperty(value = "代码")
        private String bondId;
        @ExcelProperty(value = "名称")
        private String bondName;

        @ColumnWidth(15)
        @ExcelProperty(value = "数据日期")
        private LocalDate date;
        //@ExcelProperty(value = "开盘")
        private BigDecimal beginPrice;

        //@ExcelProperty(value = "收盘")
        private BigDecimal endPrice;
        //@ExcelProperty(value = "涨跌额")
        private BigDecimal incrPrice;
        @ColumnWidth(15)
        @ExcelProperty(value = "涨跌幅(%)")
        private BigDecimal incrAmount;

        private BigDecimal minPrice;

        private BigDecimal maxPrice;

        /**
         * 成交金额(万)
         */
        private BigDecimal volumes;
        //
        @ExcelProperty(value = "成交量")
        private BigDecimal volume;

        public static HistDetailDTO parse(List<String> lines) {
            if (CollectionUtils.isEmpty(lines)) {
                return null;
            }

            HistDetailDTO histDetailDTO = new HistDetailDTO();
            histDetailDTO.setDate(LocalDateTimeUtil.parseDate(lines.get(0), "yyyMMdd"));
            histDetailDTO.setBeginPrice(new BigDecimal(lines.get(1)));
            histDetailDTO.setEndPrice(new BigDecimal(lines.get(2)));

            histDetailDTO.setMaxPrice(new BigDecimal(lines.get(3)));
            histDetailDTO.setMinPrice(new BigDecimal(lines.get(4)));
            histDetailDTO.setVolume(new BigDecimal(lines.get(5)));
            histDetailDTO.setVolumes(new BigDecimal(lines.get(6)));

            histDetailDTO.setIncrPrice(new BigDecimal(lines.get(8)));
            histDetailDTO.setIncrAmount(new BigDecimal(StringUtil.replace(lines.get(9), "%", "")));
            return histDetailDTO;
        }

    }
}
